home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr44 / frasrc19.zip / REALDOS.C < prev    next >
Text File  |  1995-03-04  |  57KB  |  1,886 lines

  1. /*
  2.     Miscellaneous C routines used only in DOS Fractint.
  3. */
  4.  
  5. #include <string.h>
  6. #include <stdio.h>
  7. #ifndef XFRACT
  8. #include <dos.h>
  9. #include <io.h>
  10. #include <process.h>
  11. #endif
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. #include <fcntl.h>
  15. #include <math.h>
  16. #include <stdlib.h>
  17. #include <ctype.h>
  18. #include "fractint.h"
  19. #include "fractype.h"
  20. #include "helpdefs.h"
  21. #include "prototyp.h"
  22.  
  23. static int menu_checkkey(int curkey,int choice);
  24.  
  25. /* uncomment following for book version */
  26. /* #define WAITE */
  27.  
  28. int release=1900; /* this has 2 implied decimals; increment it every synch */
  29. int patchlevel=0; /* patchlevel for DOS version */
  30. #ifdef XFRACT
  31. int xrelease=300;
  32. #endif
  33.  
  34. /* fullscreen_choice options */
  35. #define CHOICERETURNKEY 1
  36. #define CHOICEMENU    2
  37. #define CHOICEHELP    4
  38. #define CHOICESCRUNCH    16
  39. #define CHOICESNOTSORTED 32
  40.  
  41. /* int stopmsg(flags,message) displays message and waits for a key:
  42.      message should be a max of 9 lines with \n's separating them;
  43.        no leading or trailing \n's in message;
  44.        no line longer than 76 chars for best appearance;
  45.      flag options:
  46.        &1 if already in text display mode, stackscreen is not called
  47.       and message is displayed at (12,0) instead of (4,0)
  48.        &2 if continue/cancel indication is to be returned;
  49.       when not set, "Any key to continue..." is displayed
  50.       when set, "Escape to cancel, any other key to continue..."
  51.       -1 is returned for cancel, 0 for continue
  52.        &4 set to suppress buzzer
  53.        &8 for Fractint for Windows & parser - use a fixed pitch font
  54.       &16 for info only message (green box instead of red in DOS vsn)
  55.    */
  56. #ifdef XFRACT   
  57. static char far s_errorstart[] = {"*** Error during startup:"};   
  58. #endif
  59. static char far s_escape_cancel[] = {"Escape to cancel, any other key to continue..."};
  60. static char far s_anykey[] = {"Any key to continue..."};
  61. static char far s_custom[] = {"Customized Version"}; 
  62. static char far s_notpublic[] = {"Not for Public Release"}; 
  63. int stopmsg (int flags, char far *msg)
  64. {
  65.    int ret,toprow,color,savelookatmouse;
  66.    static unsigned char batchmode = 0;
  67.    if(debugflag != 0)
  68.    {
  69.       static FILE *fp = NULL;
  70.       if(fp==NULL)
  71.          fp=dir_fopen(workdir,"stopmsg.txt","w");
  72.       else
  73.          fp=dir_fopen(workdir,"stopmsg.txt","a");
  74.       if(fp != NULL)
  75. #ifndef XRACT
  76.       fprintf(fp,"%Fs\n",msg);
  77. #else
  78.       fprintf(fp,"%s\n",msg);
  79. #endif    
  80.       fclose(fp);
  81.    }
  82.    if (active_system == 0 /* DOS */
  83.      && first_init) {      /* & cmdfiles hasn't finished 1st try */
  84. #ifdef XFRACT
  85.       setvideotext();
  86.       buzzer(2);
  87.       putstring(0,0,15,s_errorstart);
  88.       putstring(2,0,15,msg);
  89.       movecursor(8,0);
  90.       sleep(1);
  91.       UnixDone();
  92.       exit(1);
  93. #else
  94.       printf("%Fs\n",msg);
  95.       dopause(1); /* pause deferred until after cmdfiles */
  96.       return(0);
  97. #endif
  98.       }
  99.    if (initbatch >= 1 || batchmode) { /* in batch mode */
  100.       initbatch = 4; /* used to set errorlevel */
  101.       batchmode = 1; /* fixes *second* stopmsg in batch mode bug */
  102.       return (-1);
  103.       }
  104.    ret = 0;
  105.    savelookatmouse = lookatmouse;
  106.    lookatmouse = -13;
  107.    if ((flags & 1))
  108.       blankrows(toprow=12,10,7);
  109.    else {
  110.       stackscreen();
  111.       toprow = 4;
  112.       movecursor(4,0);
  113.       }
  114.    textcbase = 2; /* left margin is 2 */
  115.    putstring(toprow,0,7,msg);
  116.    if (flags & 2)
  117.       putstring(textrow+2,0,7,s_escape_cancel);
  118.    else
  119.       putstring(textrow+2,0,7,s_anykey);
  120.    textcbase = 0; /* back to full line */
  121.    color = (flags & 16) ? C_STOP_INFO : C_STOP_ERR;
  122.    setattr(toprow,0,color,(textrow+1-toprow)*80);
  123.    movecursor(25,80);    /* cursor off */
  124.    if ((flags & 4) == 0)
  125.       buzzer((flags & 16) ? 0 : 2);
  126.    while (keypressed()) /* flush any keyahead */
  127.       getakey();
  128.    if(debugflag != 324)
  129.       if (getakeynohelp() == ESC)
  130.          ret = -1;
  131.    if ((flags & 1))
  132.       blankrows(toprow,10,7);
  133.    else
  134.       unstackscreen();
  135.    lookatmouse = savelookatmouse;
  136.    return ret;
  137. }
  138.  
  139.  
  140. static char far *temptextsave = NULL;
  141. static int  textxdots,textydots;
  142.  
  143. /* texttempmsg(msg) displays a text message of up to 40 characters, waits
  144.       for a key press, restores the prior display, and returns (without
  145.       eating the key).
  146.       It works in almost any video mode - does nothing in some very odd cases
  147.       (HCGA hi-res with old bios), or when there isn't 10k of temp mem free. */
  148. int texttempmsg(char far *msgparm)
  149. {
  150.    if (showtempmsg(msgparm))
  151.       return(-1);
  152. #ifndef XFRACT
  153.    while (!keypressed()) ; /* wait for a keystroke but don't eat it */
  154. #else
  155.    waitkeypressed(0); /* wait for a keystroke but don't eat it */
  156. #endif
  157.    cleartempmsg();
  158.    return(0);
  159. }
  160.  
  161. void freetempmsg()
  162. {
  163.    if(temptextsave != NULL)
  164.       farmemfree(temptextsave);
  165.    temptextsave = NULL;
  166. }
  167.  
  168. int showtempmsg(char far *msgparm)
  169. {
  170.    static long size = 0;
  171.    char msg[41];
  172.    BYTE buffer[640];
  173.    char far *fartmp;
  174.    BYTE far *fontptr;
  175.    BYTE *bufptr;
  176.    int i,j,k,fontchar,charnum;
  177.    int xrepeat = 0;
  178.    int yrepeat = 0;
  179.    int save_sxoffs,save_syoffs;
  180.    far_strncpy(msg,msgparm,40);
  181.    msg[40] = 0; /* ensure max message len of 40 chars */
  182.    if (dotmode == 11) { /* disk video, screen in text mode, easy */
  183.       dvid_status(0,msg);
  184.       return(0);
  185.       }
  186.    if (active_system == 0 /* DOS */
  187.      && first_init) {      /* & cmdfiles hasn't finished 1st try */
  188.       printf("%s\n",msg);
  189.       return(0);
  190.       }
  191.  
  192.    if ((fontptr = findfont(0)) == NULL) { /* old bios, no font table? */
  193.       if (oktoprint == 0           /* can't printf */
  194.     || sxdots > 640 || sydots > 200) /* not willing to trust char cell size */
  195.      return(-1); /* sorry, message not displayed */
  196.       textydots = 8;
  197.       textxdots = sxdots;
  198.       }
  199.    else {
  200.       xrepeat = (sxdots >= 640) ? 2 : 1;
  201.       yrepeat = (sydots >= 300) ? 2 : 1;
  202.       textxdots = strlen(msg) * xrepeat * 8;
  203.       textydots = yrepeat * 8;
  204.       }
  205.    /* worst case needs 10k */
  206.    if(temptextsave != NULL)
  207.       if(size != (long)textxdots * (long)textydots)
  208.          freetempmsg();
  209.    size = (long)textxdots * (long)textydots;
  210.    save_sxoffs = sxoffs;
  211.    save_syoffs = syoffs;
  212.    sxoffs = syoffs = 0;
  213.    if(temptextsave == NULL) /* only save screen first time called */
  214.    {
  215.       if ((temptextsave = farmemalloc(size)) == NULL)
  216.          return(-1); /* sorry, message not displayed */
  217.       fartmp = temptextsave;
  218.       for (i = 0; i < textydots; ++i) {
  219.          get_line(i,0,textxdots-1,buffer);
  220.          for (j = 0; j < textxdots; ++j) /* copy it out to far memory */
  221.          *(fartmp++) = buffer[j];
  222.          }
  223.       }
  224.    if (fontptr == NULL) { /* bios must do it for us */
  225.       home();
  226.       printf(msg);
  227.       }
  228.    else { /* generate the characters */
  229.       find_special_colors(); /* get color_dark & color_medium set */
  230.       for (i = 0; i < 8; ++i) {
  231.      memset(buffer,color_dark,640);
  232.      bufptr = buffer;
  233.      charnum = -1;
  234.      while (msg[++charnum] != 0) {
  235.         fontchar = *(fontptr + msg[charnum]*8 + i);
  236.         for (j = 0; j < 8; ++j) {
  237.            for (k = 0; k < xrepeat; ++k) {
  238.           if ((fontchar & 0x80) != 0)
  239.              *bufptr = (BYTE)color_medium;
  240.           ++bufptr;
  241.           }
  242.            fontchar <<= 1;
  243.            }
  244.         }
  245.      for (j = 0; j < yrepeat; ++j)
  246.         put_line(i*yrepeat+j,0,textxdots-1,buffer);
  247.      }
  248.       }
  249.    sxoffs = save_sxoffs;
  250.    syoffs = save_syoffs;
  251.    return(0);
  252. }
  253.  
  254. void cleartempmsg()
  255. {
  256.    BYTE buffer[640];
  257.    char far *fartmp;
  258.    int i,j;
  259.    int save_sxoffs,save_syoffs;
  260.    if (dotmode == 11) /* disk video, easy */
  261.       dvid_status(0,"");
  262.    else if (temptextsave != NULL) {
  263.       save_sxoffs = sxoffs;
  264.       save_syoffs = syoffs;
  265.       sxoffs = syoffs = 0;
  266.       fartmp = temptextsave;
  267.       for (i = 0; i < textydots; ++i) {
  268.      for (j = 0; j < textxdots; ++j) /* copy back from far memory */
  269.         buffer[j] = *(fartmp++);
  270.      put_line(i,0,textxdots-1,buffer);
  271.      }
  272.      if(using_jiim == 0)  /* jiim frees memory with freetempmsg() */
  273.      {
  274.          farmemfree(temptextsave);
  275.          temptextsave = NULL;
  276.       }
  277.       sxoffs = save_sxoffs;
  278.       syoffs = save_syoffs;
  279.       }
  280. }
  281.  
  282.  
  283. void blankrows(int row,int rows,int attr)
  284. {
  285.    char buf[81];
  286.    memset(buf,' ',80);
  287.    buf[80] = 0;
  288.    while (--rows >= 0)
  289.       putstring(row++,0,attr,buf);
  290.    }
  291.  
  292.  
  293. void helptitle()
  294. {
  295.    char msg[80],buf[80];
  296.    setclear(); /* clear the screen */
  297. #ifdef XFRACT
  298.    sprintf(msg,"XFRACTINT  Version %d.%02d (FRACTINT Version %d.%02d)",
  299.            xrelease/100,xrelease%100, release/100,release%100);
  300.    putstringcenter(0,0,80,C_TITLE,msg);
  301. #else
  302. #ifdef WAITE
  303.    release=1900;
  304.    patchlevel = 0;
  305. #endif
  306.    /*
  307.    sprintf(msg,"Special FRACTINT Version %d.%01d",release/100,(release%100)/10);
  308.    */
  309.    sprintf(msg,"FRACTINT Version %d.%01d",release/100,(release%100)/10);
  310.    if (release%10) {
  311.       sprintf(buf,"%01d",release%10);
  312.       strcat(msg,buf);
  313.       }
  314. #ifndef XFRACT
  315.    if (patchlevel) {
  316.       sprintf(buf," Patch %d",patchlevel);
  317.       strcat(msg,buf);
  318.       }
  319. #endif
  320. #if 0 /*WAITE*/ /* realdos.c */
  321.    strcat(msg," for the Waite Group's Image Lab 2nd Edition");
  322. #endif /* WAITE - realdos.c */
  323.    putstringcenter(0,0,80,C_TITLE,msg);
  324. #ifdef WAITE
  325.    return;
  326. #endif
  327. #endif
  328. /* uncomment next for production executable: */
  329.    /* return; */ 
  330.    /*NOTREACHED*/
  331.    if (debugflag == 3002) return;
  332. /* putstring(0,2,C_TITLE_DEV,"Development Version"); */
  333. /* replace above by next after creating production release, for release source */
  334.    putstring(0,3,C_TITLE_DEV, s_custom); 
  335.    putstring(0,55,C_TITLE_DEV,s_notpublic); 
  336. }
  337.  
  338.  
  339. int putstringcenter(int row, int col, int width, int attr, char far *msg)
  340. {
  341.    char buf[81];
  342.    int i,j,k;
  343.    i = 0;
  344. #ifdef XFRACT
  345.    if (width==80) width=79; /* Some systems choke in column 80 */
  346. #endif
  347.    while (msg[i]) ++i; /* strlen for a far */
  348.    if (i == 0) return(-1);
  349.    j = (width - i) / 2;
  350.    j -= (width + 10 - i) / 20; /* when wide a bit left of center looks better */
  351.    memset(buf,' ',width);
  352.    buf[width] = 0;
  353.    i = 0;
  354.    k = j;
  355.    while (msg[i]) buf[k++] = msg[i++]; /* strcpy for a far */
  356.    putstring(row,col,attr,buf);
  357.    return j;
  358. }
  359.  
  360.  
  361. #ifndef XFRACT
  362. static int screenctr = -1;
  363. #else
  364. static int screenctr = 0;
  365. #endif
  366. #define MAXSCREENS 3
  367. static BYTE far *savescreen[MAXSCREENS];
  368. static int saverc[MAXSCREENS+1];
  369. static FILE *savescf = NULL;
  370. static char scsvfile[]="fractscr.tmp";
  371.  
  372. void stackscreen()
  373. {
  374. #ifndef XFRACT
  375.    BYTE far *vidmem;
  376.    int savebytes;
  377.    int i;
  378.    BYTE far *ptr;
  379.    char buf[256];
  380.    memcpy(buf,suffix,256);
  381.    saverc[screenctr+1] = textrow*80 + textcol;
  382.    if (++screenctr) { /* already have some stacked */
  383.      static char far msg[]={"stackscreen overflow"};
  384.       if ((i = screenctr - 1) >= MAXSCREENS) { /* bug, missing unstack? */
  385.      stopmsg(1,msg);
  386.      exit(1);
  387.      }
  388.       vidmem = MK_FP(textaddr,0);
  389.       savebytes = (text_type == 0) ? 4000 : 16384;
  390.       if ((ptr = savescreen[i] = farmemalloc((long)savebytes)) != NULL)
  391.      far_memcpy(ptr,vidmem,savebytes);
  392.       else {
  393.      if (savescf == NULL) { /* create file just once */
  394.         if ((savescf = dir_fopen(tempdir,scsvfile,"wb")) == NULL)
  395.            goto fileproblem;
  396.         if (fwrite(buf,MAXSCREENS,16384,savescf) != 16384)
  397.            goto fileproblem;
  398.         fclose(savescf);
  399.         if ((savescf = dir_fopen(tempdir,scsvfile,"r+b")) == NULL) {
  400.         static char far msg[]={"insufficient memory, aborting"};
  401. fileproblem:   stopmsg(1,msg);
  402.            exit(1);
  403.            }
  404.         }
  405.      fseek(savescf,(long)(savebytes*i),SEEK_SET);
  406.      while (--savebytes >= 0)
  407.         putc(*(vidmem++),savescf);
  408.      }
  409.       setclear();
  410.       }
  411.    else
  412.       setfortext();
  413.    memcpy(suffix,buf,256);
  414. #else
  415.    int i;
  416.    BYTE far *ptr;
  417.    saverc[screenctr+1] = textrow*80 + textcol;
  418.    if (++screenctr) { /* already have some stacked */
  419.          static char far msg[]={"stackscreen overflow"};
  420.       if ((i = screenctr - 1) >= MAXSCREENS) { /* bug, missing unstack? */
  421.          stopmsg(1,msg);
  422.          exit(1);
  423.          }
  424.       if (ptr = savescreen[i] = farmemalloc(sizeof(int *)))
  425.          savecurses(ptr);
  426.       else {
  427.          stopmsg(1,msg);
  428.          exit(1);
  429.         }
  430.       setclear();
  431.       }
  432.    else
  433.       setfortext();
  434. #endif
  435. }
  436.  
  437. void unstackscreen()
  438. {
  439. #ifndef XFRACT
  440.    char far *vidmem;
  441.    int savebytes;
  442.    BYTE far *ptr;
  443.    char buf[256];
  444.    memcpy(buf,suffix,256);
  445.    textrow = saverc[screenctr] / 80;
  446.    textcol = saverc[screenctr] % 80;
  447.    if (--screenctr >= 0) { /* unstack */
  448.       vidmem = MK_FP(textaddr,0);
  449.       savebytes = (text_type == 0) ? 4000 : 16384;
  450.       if ((ptr = savescreen[screenctr]) != NULL) {
  451.      far_memcpy(vidmem,ptr,savebytes);
  452.      farmemfree(ptr);
  453.      }
  454.       else {
  455.      fseek(savescf,(long)(savebytes*screenctr),SEEK_SET);
  456.      while (--savebytes >= 0)
  457.         *(vidmem++) = (BYTE)getc(savescf);
  458.      }
  459.       }
  460.    else
  461.       setforgraphics();
  462.    movecursor(-1,-1);
  463.    memcpy(suffix,buf,256);
  464. #else
  465.    BYTE far *ptr;
  466.    textrow = saverc[screenctr] / 80;
  467.    textcol = saverc[screenctr] % 80;
  468.    if (--screenctr >= 0) { /* unstack */
  469.       ptr = savescreen[screenctr];
  470.       restorecurses(ptr);
  471.       farmemfree(ptr);
  472.       }
  473.    else
  474.       setforgraphics();
  475.    movecursor(-1,-1);
  476. #endif
  477. }
  478.  
  479. void discardscreen()
  480. {
  481.    if (--screenctr >= 0) { /* unstack */
  482.       if (savescreen[screenctr])
  483.      farmemfree(savescreen[screenctr]);
  484.       }
  485.    else
  486.       discardgraphics();
  487. }
  488.  
  489.  
  490. /* ------------------------------------------------------------------------ */
  491.  
  492. char speed_prompt[]="Speed key string";
  493.  
  494. int fullscreen_choice(
  495.     int options,              /* &2 use menu coloring scheme            */
  496.                                   /* &4 include F1 for help in instructions */
  497.                                   /* &8 add caller's instr after normal set */
  498.                                   /* &16 menu items up one line             */
  499.     char far *hdg,              /* heading info, \n delimited             */
  500.     char far *hdg2,              /* column heading or NULL                 */
  501.     char far *instr,              /* instructions, \n delimited, or NULL    */
  502.     int numchoices,               /* How many choices in list               */
  503.     char far*far*choices,         /* array of choice strings                */
  504.     int far *attributes,          /* &3: 0 normal color, 1,3 highlight      */
  505.                                   /* &256 marks a dummy entry               */
  506.     int boxwidth,              /* box width, 0 for calc (in items)       */
  507.     int boxdepth,              /* box depth, 0 for calc, 99 for max      */
  508.     int colwidth,              /* data width of a column, 0 for calc     */
  509.     int current,                  /* start with this item                   */
  510.     void (*formatitem)(int,char*),/* routine to display an item or NULL     */
  511.     char *speedstring,            /* returned speed key value, or NULL      */
  512.     int (*speedprompt)(int,int,int,char *,int),/* routine to display prompt or NULL      */
  513.     int (*checkkey)(int,int)      /* routine to check keystroke or NULL     */
  514. )
  515.     /* return is: n>=0 for choice n selected,
  516.                   -1 for escape
  517.                   k for checkkey routine return value k (if not 0 nor -1)
  518.                   speedstring[0] != 0 on return if string is present
  519.     */
  520. {
  521. static char far choiceinstr1a[]="Use the cursor keys to highlight your selection";
  522. static char far choiceinstr1b[]="Use the cursor keys or type a value to make a selection";
  523. static char far choiceinstr2a[]="Press ENTER for highlighted choice, or ESCAPE to back out";
  524. static char far choiceinstr2b[]="Press ENTER for highlighted choice, ESCAPE to back out, or F1 for help";
  525. static char far choiceinstr2c[]="Press ENTER for highlighted choice, or F1 for help";
  526.  
  527.    int titlelines,titlewidth;
  528.    int reqdrows;
  529.    int topleftrow,topleftcol;
  530.    int topleftchoice;
  531.    int speedrow = 0;  /* speed key prompt */
  532.    int boxitems;      /* boxwidth*boxdepth */
  533.    int curkey,increment,rev_increment = 0;
  534.    int redisplay;
  535.    int i,j,k = 0;
  536.    char far *charptr;
  537.    char buf[81];
  538.    int speed_match = 0;
  539.    char curitem[81];
  540.    char far *itemptr;
  541.    int ret,savelookatmouse;
  542.    int scrunch;  /* scrunch up a line */
  543.  
  544.    if(options&CHOICESCRUNCH)
  545.       scrunch = 1;
  546.    else
  547.       scrunch = 0;
  548.    savelookatmouse = lookatmouse;
  549.    lookatmouse = 0;
  550.    ret = -1;
  551.    if (speedstring
  552.      && (i = strlen(speedstring)) > 0) { /* preset current to passed string */
  553.       current = 0;
  554.       if(options&CHOICESNOTSORTED)
  555.       { 
  556.          while (current < numchoices
  557.          && (k = strncasecmp(speedstring,choices[current],i)) != 0)
  558.         ++current;
  559.          if(k != 0)
  560.             current = 0;
  561.       }
  562.       else
  563.       {
  564.          while (current < numchoices
  565.          && (k = strncasecmp(speedstring,choices[current],i)) > 0)
  566.         ++current;
  567.          if (k < 0 && current > 0)  /* oops - overshot */
  568.         --current;
  569.       }
  570.       if (current >= numchoices) /* bumped end of list */
  571.      current = numchoices - 1;
  572.    }
  573.  
  574.    for(;;) {
  575.       if (current >= numchoices)  /* no real choice in the list? */
  576.      goto fs_choice_end;
  577.       if ((attributes[current] & 256) == 0)
  578.      break;
  579.       ++current;          /* scan for a real choice */
  580.       }
  581.  
  582.    titlelines = titlewidth = 0;
  583.    if (hdg) {
  584.       charptr = hdg;          /* count title lines, find widest */
  585.       i = 0;
  586.       titlelines = 1;
  587.       while (*charptr) {
  588.      if (*(charptr++) == '\n') {
  589.         ++titlelines;
  590.         i = -1;
  591.         }
  592.      if (++i > titlewidth)
  593.         titlewidth = i;
  594.      }
  595.       }
  596.  
  597.    if (colwidth == 0)          /* find widest column */
  598.       for (i = 0; i < numchoices; ++i)
  599.       {
  600.          int len;
  601.      if ((len=far_strlen(choices[i])) > colwidth)
  602.         colwidth = len;
  603.       }
  604.    /* title(1), blank(1), hdg(n), blank(1), body(n), blank(1), instr(?) */
  605.    reqdrows = 3 - scrunch;          /* calc rows available */
  606.    if (hdg)
  607.       reqdrows += titlelines + 1;
  608.    if (instr) {           /* count instructions lines */
  609.       charptr = instr;
  610.       ++reqdrows;
  611.       while (*charptr)
  612.      if (*(charptr++) == '\n')
  613.         ++reqdrows;
  614.       if ((options & 8))      /* show std instr too */
  615.      reqdrows += 2;
  616.       }
  617.    else
  618.       reqdrows += 2;          /* standard instructions */
  619.    if (speedstring) ++reqdrows;   /* a row for speedkey prompt */
  620.    if (boxdepth > (i = 25 - reqdrows)) /* limit the depth to max */
  621.       boxdepth = i;
  622.    if (boxwidth == 0) {       /* pick box width and depth */
  623.       if (numchoices <= i - 2) {  /* single column is 1st choice if we can */
  624.      boxdepth = numchoices;
  625.      boxwidth = 1;
  626.      }
  627.       else {              /* sort-of-wide is 2nd choice */
  628.      boxwidth = 60 / (colwidth + 1);
  629.      if (boxwidth == 0
  630.        || (boxdepth = (numchoices+boxwidth-1)/boxwidth) > i - 2) {
  631.         boxwidth = 80 / (colwidth + 1); /* last gasp, full width */
  632.         if ((boxdepth = (numchoices+boxwidth-1)/boxwidth) > i)
  633.            boxdepth = i;
  634.         }
  635.      }
  636.       }
  637.    if ((i = 77 / boxwidth - colwidth) > 3) /* spaces to add @ left each choice */
  638.       i = 3;
  639.    j = boxwidth * (colwidth += i) + i;       /* overall width of box */
  640.    if (j < titlewidth+2)
  641.       j = titlewidth + 2;
  642.    if (j > 80)
  643.       j = 80;
  644.    if (j <= 70 && boxwidth == 2) {       /* special case makes menus nicer */
  645.       ++j;
  646.       ++colwidth;
  647.       }
  648.    k = (80 - j) / 2;               /* center the box */
  649.    k -= (90 - j) / 20;
  650.    topleftcol = k + i;               /* column of topleft choice */
  651.    i = (25 - reqdrows - boxdepth) / 2;
  652.    i -= i / 4;                   /* higher is better if lots extra */
  653.    topleftrow = 3 + titlelines + i;       /* row of topleft choice */
  654.     
  655.    /* now set up the overall display */
  656.    helptitle();                /* clear, display title line */
  657.    setattr(1,0,C_PROMPT_BKGRD,24*80);       /* init rest to background */
  658.    for (i = topleftrow-1-titlelines; i < topleftrow+boxdepth+1; ++i)
  659.       setattr(i,k,C_PROMPT_LO,j);       /* draw empty box */
  660.    if (hdg) {
  661.       textcbase = (80 - titlewidth) / 2;   /* set left margin for putstring */
  662.       textcbase -= (90 - titlewidth) / 20; /* put heading into box */
  663.       putstring(topleftrow-titlelines-1,0,C_PROMPT_HI,hdg);
  664.       textcbase = 0;
  665.       }
  666.    if (hdg2)                   /* display 2nd heading */
  667.       putstring(topleftrow-1,topleftcol,C_PROMPT_MED,hdg2);
  668.    i = topleftrow + boxdepth + 1;
  669.    if (instr == NULL || (options & 8)) {   /* display default instructions */
  670.       if (i < 20) ++i;
  671.       if (speedstring) {
  672.      speedrow = i;
  673.      *speedstring = 0;
  674.      if (++i < 22) ++i;
  675.      }
  676.       i -= scrunch;
  677.       putstringcenter(i++,0,80,C_PROMPT_BKGRD,
  678.         (speedstring) ? choiceinstr1b : choiceinstr1a);
  679.       putstringcenter(i++,0,80,C_PROMPT_BKGRD,
  680.         (options&CHOICEMENU) ? choiceinstr2c
  681.         : ((options&CHOICEHELP) ? choiceinstr2b : choiceinstr2a));
  682.       }
  683.    if (instr) {                /* display caller's instructions */
  684.       charptr = instr;
  685.       j = -1;
  686.       while ((buf[++j] = *(charptr++)) != 0)
  687.      if (buf[j] == '\n') {
  688.         buf[j] = 0;
  689.         putstringcenter(i++,0,80,C_PROMPT_BKGRD,buf);
  690.         j = -1;
  691.         }
  692.       putstringcenter(i,0,80,C_PROMPT_BKGRD,buf);
  693.       }
  694.  
  695.    boxitems = boxwidth * boxdepth;
  696.    topleftchoice = 0;               /* pick topleft for init display */
  697.    while (current - topleftchoice >= boxitems
  698.      || (current - topleftchoice > boxitems/2
  699.      && topleftchoice + boxitems < numchoices))
  700.       topleftchoice += boxwidth;
  701.    redisplay = 1;
  702.    topleftrow -= scrunch;
  703.    for(;;) { /* main loop */
  704.  
  705.       if (redisplay) {                 /* display the current choices */
  706.      if ((options & CHOICEMENU) == 0) {
  707.         memset(buf,' ',80);
  708.         buf[boxwidth*colwidth] = 0;
  709.         for (i = (hdg2) ? 0 : -1; i <= boxdepth; ++i)  /* blank the box */
  710.            putstring(topleftrow+i,topleftcol,C_PROMPT_LO,buf);
  711.         }
  712.      for (i = 0; i+topleftchoice < numchoices && i < boxitems; ++i) {
  713.         /* display the choices */
  714.         if ((k = attributes[j = i+topleftchoice] & 3) == 1)
  715.            k = C_PROMPT_LO;
  716.         else if (k == 3)
  717.            k = C_PROMPT_HI;
  718.         else
  719.            k = C_PROMPT_MED;
  720.         if (formatitem)
  721.         {
  722.            (*formatitem)(j,buf);
  723.            charptr=buf;
  724.         }   
  725.         else
  726.            charptr = choices[j];
  727.         putstring(topleftrow+i/boxwidth,topleftcol+(i%boxwidth)*colwidth,
  728.               k,charptr);
  729.         }
  730.      /***
  731.      ... format differs for summary/detail, whups, force box width to
  732.      ...  be 72 when detail toggle available?  (2 grey margin each
  733.      ...  side, 1 blue margin each side)
  734.      ***/
  735.      if (topleftchoice > 0 && hdg2 == NULL)
  736.         putstring(topleftrow-1,topleftcol,C_PROMPT_LO,"(more)");
  737.      if (topleftchoice + boxitems < numchoices)
  738.         putstring(topleftrow+boxdepth,topleftcol,C_PROMPT_LO,"(more)");
  739.      redisplay = 0;
  740.      }
  741.  
  742.       i = current - topleftchoice;         /* highlight the current choice */
  743.       if (formatitem)
  744.       {
  745.      (*formatitem)(current,curitem);
  746.      itemptr=curitem;
  747.       }
  748.       else
  749.      itemptr = choices[current];
  750.       putstring(topleftrow+i/boxwidth,topleftcol+(i%boxwidth)*colwidth,
  751.         C_CHOICE_CURRENT,itemptr);
  752.  
  753.       if (speedstring) {             /* show speedstring if any */
  754.      memset(buf,' ',80);
  755.      buf[80] = 0;
  756.      putstring(speedrow,0,C_PROMPT_BKGRD,buf);
  757.      if (*speedstring) {             /* got a speedstring on the go */
  758.         putstring(speedrow,15,C_CHOICE_SP_INSTR," ");
  759.         if (speedprompt)
  760.            j = speedprompt(speedrow,16,C_CHOICE_SP_INSTR,speedstring,speed_match);
  761.         else {
  762.            putstring(speedrow,16,C_CHOICE_SP_INSTR,speed_prompt);
  763.            j = strlen(speed_prompt);
  764.            }
  765.         strcpy(buf,speedstring);
  766.         i = strlen(buf);
  767.         while (i < 30)
  768.            buf[i++] = ' ';
  769.         buf[i] = 0;
  770.         putstring(speedrow,16+j,C_CHOICE_SP_INSTR," ");
  771.         putstring(speedrow,17+j,C_CHOICE_SP_KEYIN,buf);
  772.         movecursor(speedrow,17+j+strlen(speedstring));
  773.         }
  774.      else
  775.         movecursor(25,80);
  776.      }
  777.       else
  778.      movecursor(25,80);
  779.  
  780. #ifndef XFRACT
  781.       while (!keypressed()) { } /* enables help */
  782. #else
  783.       waitkeypressed(0); /* enables help */
  784. #endif
  785.       curkey = getakey();
  786. #ifdef XFRACT
  787.       if (curkey==F10) curkey=')';
  788.       if (curkey==F9) curkey='(';
  789.       if (curkey==F8) curkey='*';
  790. #endif
  791.  
  792.       i = current - topleftchoice;         /* unhighlight current choice */
  793.       if ((k = attributes[current] & 3) == 1)
  794.      k = C_PROMPT_LO;
  795.       else if (k == 3)
  796.      k = C_PROMPT_HI;
  797.       else
  798.      k = C_PROMPT_MED;
  799.       putstring(topleftrow+i/boxwidth,topleftcol+(i%boxwidth)*colwidth,
  800.         k,itemptr);
  801.  
  802.       increment = 0;
  803.       switch (curkey) {              /* deal with input key */
  804.      case ENTER:
  805.      case ENTER_2:
  806.         ret = current;
  807.         goto fs_choice_end;
  808.      case ESC:
  809.         goto fs_choice_end;
  810.      case DOWN_ARROW:
  811.      case DOWN_ARROW_2:
  812.         rev_increment = 0 - (increment = boxwidth);
  813.         break;
  814.      case UP_ARROW:
  815.      case UP_ARROW_2:
  816.         increment = 0 - (rev_increment = boxwidth);
  817.         break;
  818.      case RIGHT_ARROW:
  819.      case RIGHT_ARROW_2:
  820.         if (boxwidth == 1) break;
  821.         increment = 1; rev_increment = -1;
  822.         break;
  823.      case LEFT_ARROW:
  824.      case LEFT_ARROW_2:
  825.         if (boxwidth == 1) break;
  826.         increment = -1; rev_increment = 1;
  827.         break;
  828.      case PAGE_UP:
  829.         if (numchoices > boxitems) {
  830.            topleftchoice -= boxitems;
  831.            increment = -boxitems;
  832.            rev_increment = boxwidth;
  833.            redisplay = 1;
  834.            }
  835.         break;
  836.      case PAGE_DOWN:
  837.         if (numchoices > boxitems) {
  838.            topleftchoice += boxitems;
  839.            increment = boxitems;
  840.            rev_increment = -boxwidth;
  841.            redisplay = 1;
  842.            }
  843.         break;
  844.      case CTL_HOME:
  845.      case HOME:
  846.         current = -1;
  847.         increment = rev_increment = 1;
  848.         break;
  849.      case CTL_END:
  850.      case END:
  851.         current = numchoices;
  852.         increment = rev_increment = -1;
  853.         break;
  854.      default:
  855.         if (checkkey) {
  856.            if ((ret = (*checkkey)(curkey,current)) < -1 || ret > 0)
  857.           goto fs_choice_end;
  858.            if (ret == -1)
  859.           redisplay = -1;
  860.            }
  861.         ret = -1;
  862.         if (speedstring) {
  863.            i = strlen(speedstring);
  864.            if (curkey == 8 && i > 0) /* backspace */
  865.           speedstring[--i] = 0;
  866.            if (33 <= curkey && curkey <= 126 && i < 30) {
  867.           curkey = tolower(curkey);
  868.           speedstring[i] = (char)curkey;
  869.           speedstring[++i] = 0;
  870.           }
  871.            if (i > 0) {         /* locate matching type */
  872.           current = 0;
  873.           while (current < numchoices
  874.             && (speed_match = strncasecmp(speedstring,choices[current],i)) > 0)
  875.              ++current;
  876.           if (speed_match < 0 && current > 0)  /* oops - overshot */
  877.              --current;
  878.           if (current >= numchoices) /* bumped end of list */
  879.              current = numchoices - 1;
  880.           }
  881.            }
  882.         break;
  883.      }
  884.  
  885.       if (increment) {            /* apply cursor movement */
  886.      current += increment;
  887.      if (speedstring)        /* zap speedstring */
  888.         speedstring[0] = 0;
  889.      }
  890.       for(;;) {            /* adjust to a non-comment choice */
  891.      if (current < 0 || current >= numchoices)
  892.          increment = rev_increment;
  893.      else if ((attributes[current] & 256) == 0)
  894.          break;
  895.      current += increment;
  896.      }
  897.       if (topleftchoice > numchoices - boxitems)
  898.      topleftchoice = ((numchoices+boxwidth-1)/boxwidth)*boxwidth - boxitems;
  899.       if (topleftchoice < 0)
  900.      topleftchoice = 0;
  901.       while (current < topleftchoice) {
  902.      topleftchoice -= boxwidth;
  903.      redisplay = 1;
  904.      }
  905.       while (current >= topleftchoice + boxitems) {
  906.      topleftchoice += boxwidth;
  907.      redisplay = 1;
  908.      }
  909.       }
  910.  
  911. fs_choice_end:
  912.    lookatmouse = savelookatmouse;
  913.    return(ret);
  914.  
  915. }
  916.  
  917. #if (_MSC_VER >= 700)
  918. #pragma code_seg ("realdos1_text")     /* place following in an overlay */
  919. #endif
  920.  
  921. /* squeeze space out of string */
  922. char *despace(char *str)
  923. {
  924.       char *obuf, *nbuf;
  925.  
  926.       for (obuf = str, nbuf = str; *obuf && obuf; ++obuf)
  927.       {
  928.             if (!isspace(*obuf))
  929.                   *nbuf++ = *obuf;
  930.       }
  931.       *nbuf = 0;
  932.       return str;
  933. }
  934.  
  935. #ifndef XFRACT
  936. /* case independent version of strncmp */
  937. int strncasecmp(char far *s,char far *t,int ct)
  938. {
  939.    for(; (tolower(*s) == tolower(*t)) && --ct ; s++,t++)
  940.       if(*s == '\0')
  941.      return(0);
  942.    return(tolower(*s) - tolower(*t));
  943. }
  944. #endif
  945.  
  946. #define LOADPROMPTSCHOICES(X,Y)     {\
  947.    static FCODE tmp[] = { Y };\
  948.    choices[X]= (char far *)tmp;\
  949.    }
  950.  
  951. static int menutype;
  952. #define MENU_HDG 3
  953. #define MENU_ITEM 1
  954.  
  955. int main_menu(int fullmenu)
  956. {
  957.    char far *choices[44]; /* 2 columns * 22 rows */
  958.    int attributes[44];
  959.    int choicekey[44];
  960.    int i;
  961.    int nextleft,nextright;
  962.    int oldtabmode /* ,oldhelpmode */;
  963.    static char far MAIN_MENU[] = {"MAIN MENU"};
  964.    int showjuliatoggle; 
  965.    oldtabmode = tabmode;
  966.    /* oldhelpmode = helpmode; */
  967. top:
  968.    menutype = fullmenu;
  969.    tabmode = 0;
  970.    showjuliatoggle = 0;
  971.    for (i = 0; i < 44; ++i) {
  972.       attributes[i] = 256;
  973.       choices[i] = "";
  974.       choicekey[i] = -1;
  975.       }
  976.    nextleft = -2;
  977.    nextright = -1;
  978.  
  979.    if (fullmenu) {
  980.       LOADPROMPTSCHOICES(nextleft+=2,"      CURRENT IMAGE");
  981.       attributes[nextleft] = 256+MENU_HDG;
  982.       choicekey[nextleft+=2] = 13; /* enter */
  983.       attributes[nextleft] = MENU_ITEM;
  984.       if (calc_status == 2)
  985.       {
  986.      LOADPROMPTSCHOICES(nextleft,"continue calculation");
  987.       }
  988.       else
  989.       {
  990.      LOADPROMPTSCHOICES(nextleft,"return to image");
  991.       }
  992.       choicekey[nextleft+=2] = 9; /* tab */
  993.       attributes[nextleft] = MENU_ITEM;
  994.       LOADPROMPTSCHOICES(nextleft,"info about image      <tab>");
  995.       choicekey[nextleft+=2] = -10;
  996.       attributes[nextleft] = MENU_ITEM;
  997.       LOADPROMPTSCHOICES(nextleft,"zoom box functions...");
  998.       choicekey[nextleft+=2] = 'o';
  999.       attributes[nextleft] = MENU_ITEM;
  1000.       LOADPROMPTSCHOICES(nextleft,"orbits window          <o>");
  1001.       if(!(fractype==JULIA || fractype==JULIAFP || fractype==INVERSEJULIA))
  1002.           nextleft+=2; 
  1003.       }
  1004.    LOADPROMPTSCHOICES(nextleft+=2,"      NEW IMAGE");
  1005.    attributes[nextleft] = 256+MENU_HDG;
  1006.    choicekey[nextleft+=2] = DELETE;
  1007.    attributes[nextleft] = MENU_ITEM;
  1008.    LOADPROMPTSCHOICES(nextleft,"select video mode...  <del>");
  1009.    choicekey[nextleft+=2] = 't';
  1010.    attributes[nextleft] = MENU_ITEM;
  1011.    LOADPROMPTSCHOICES(nextleft,"select fractal type    <t>");
  1012.    if (fullmenu) {
  1013.       if ((curfractalspecific->tojulia != NOFRACTAL
  1014.       && param[0] == 0.0 && param[1] == 0.0)
  1015.       || curfractalspecific->tomandel != NOFRACTAL) {
  1016.          choicekey[nextleft+=2] = ' ';
  1017.          attributes[nextleft] = MENU_ITEM;
  1018.          LOADPROMPTSCHOICES(nextleft,"toggle to/from julia <space>");
  1019.              showjuliatoggle = 1;
  1020.       }    
  1021.       if(fractype==JULIA || fractype==JULIAFP || fractype==INVERSEJULIA) {
  1022.          choicekey[nextleft+=2] = 'j';
  1023.          attributes[nextleft] = MENU_ITEM;
  1024.          LOADPROMPTSCHOICES(nextleft,"toggle to/from inverse <j>");
  1025.          showjuliatoggle = 1;
  1026.       }
  1027.       choicekey[nextleft+=2] = 'h';
  1028.       attributes[nextleft] = MENU_ITEM;
  1029.       LOADPROMPTSCHOICES(nextleft,"return to prior image  <h>");
  1030.  
  1031.       choicekey[nextleft+=2] = 8;
  1032.       attributes[nextleft] = MENU_ITEM;
  1033.       LOADPROMPTSCHOICES(nextleft,"reverse thru history <ctl-h>");
  1034.    }
  1035.    else
  1036.       nextleft += 2;
  1037.    LOADPROMPTSCHOICES(nextleft+=2,"      OPTIONS");
  1038.    attributes[nextleft] = 256+MENU_HDG;
  1039.    choicekey[nextleft+=2] = 'x';
  1040.    attributes[nextleft] = MENU_ITEM;
  1041.    LOADPROMPTSCHOICES(nextleft,"basic options...       <x>");
  1042.    choicekey[nextleft+=2] = 'y';
  1043.    attributes[nextleft] = MENU_ITEM;
  1044.    LOADPROMPTSCHOICES(nextleft,"extended options...    <y>");
  1045.    choicekey[nextleft+=2] = 'z';
  1046.    attributes[nextleft] = MENU_ITEM;
  1047.    LOADPROMPTSCHOICES(nextleft,"type-specific parms... <z>");
  1048.    choicekey[nextleft+=2] = 'v';
  1049.    attributes[nextleft] = MENU_ITEM;
  1050.    LOADPROMPTSCHOICES(nextleft,"view window options... <v>");
  1051.    if(showjuliatoggle == 0)
  1052.    {
  1053.       choicekey[nextleft+=2] = 'i';
  1054.       attributes[nextleft] = MENU_ITEM;
  1055.       LOADPROMPTSCHOICES(nextleft,"fractal 3D parms...    <i>");
  1056.    }
  1057.    choicekey[nextleft+=2] = 2;
  1058.    attributes[nextleft] = MENU_ITEM;
  1059.    LOADPROMPTSCHOICES(nextleft,"browse parms...      <ctl-b>");
  1060.  
  1061.    LOADPROMPTSCHOICES(nextright+=2,"        FILE");
  1062.    attributes[nextright] = 256+MENU_HDG;
  1063.    choicekey[nextright+=2] = '@';
  1064.    attributes[nextright] = MENU_ITEM;
  1065.    LOADPROMPTSCHOICES(nextright,"run saved command set... <@>");
  1066.    if (fullmenu) {
  1067.       choicekey[nextright+=2] = 's';
  1068.       attributes[nextright] = MENU_ITEM;
  1069.       LOADPROMPTSCHOICES(nextright,"save image to file       <s>");
  1070.       }
  1071.    choicekey[nextright+=2] = 'r';
  1072.    attributes[nextright] = MENU_ITEM;
  1073.    LOADPROMPTSCHOICES(nextright,"load image from file...  <r>");
  1074.    choicekey[nextright+=2] = '3';
  1075.    attributes[nextright] = MENU_ITEM;
  1076.    LOADPROMPTSCHOICES(nextright,"3d transform from file...<3>");
  1077.    if (fullmenu) {
  1078.       choicekey[nextright+=2] = '#';
  1079.       attributes[nextright] = MENU_ITEM;
  1080.       LOADPROMPTSCHOICES(nextright,"3d overlay from file.....<#>");
  1081.       choicekey[nextright+=2] = 'b';
  1082.       attributes[nextright] = MENU_ITEM;
  1083.       LOADPROMPTSCHOICES(nextright,"save current parameters..<b>");
  1084.       choicekey[nextright+=2] = 'p';
  1085.       attributes[nextright] = MENU_ITEM;
  1086.       LOADPROMPTSCHOICES(nextright,"print image              <p>");
  1087.       }
  1088.    choicekey[nextright+=2] = 'd';
  1089.    attributes[nextright] = MENU_ITEM;
  1090.    LOADPROMPTSCHOICES(nextright,"shell to dos             <d>");
  1091.    choicekey[nextright+=2] = 'g';
  1092.    attributes[nextright] = MENU_ITEM;
  1093.    LOADPROMPTSCHOICES(nextright,"give command string      <g>");
  1094.    choicekey[nextright+=2] = ESC;
  1095.    attributes[nextright] = MENU_ITEM;
  1096.    LOADPROMPTSCHOICES(nextright,"quit Fractint           <esc>");
  1097.    choicekey[nextright+=2] = INSERT;
  1098.    attributes[nextright] = MENU_ITEM;
  1099.    LOADPROMPTSCHOICES(nextright,"restart Fractint        <ins>");
  1100.    if (fullmenu && gotrealdac && colors >= 16) {
  1101.       /* nextright += 2; */
  1102.       LOADPROMPTSCHOICES(nextright+=2,"       COLORS");
  1103.       attributes[nextright] = 256+MENU_HDG;
  1104.       choicekey[nextright+=2] = 'c';
  1105.       attributes[nextright] = MENU_ITEM;
  1106.       LOADPROMPTSCHOICES(nextright,"color cycling mode       <c>");
  1107.       choicekey[nextright+=2] = '+';
  1108.       attributes[nextright] = MENU_ITEM;
  1109.       LOADPROMPTSCHOICES(nextright,"rotate palette      <+>, <->");
  1110.       if (colors > 16) {
  1111.      if (!reallyega) {
  1112.         choicekey[nextright+=2] = 'e';
  1113.         attributes[nextright] = MENU_ITEM;
  1114.         LOADPROMPTSCHOICES(nextright,"palette editing mode     <e>");
  1115.         }
  1116.      choicekey[nextright+=2] = 'a';
  1117.      attributes[nextright] = MENU_ITEM;
  1118.      LOADPROMPTSCHOICES(nextright,"make starfield           <a>");
  1119.      }
  1120.       choicekey[nextright+=2] = 1;
  1121.       attributes[nextright] = MENU_ITEM;
  1122.       LOADPROMPTSCHOICES(nextright,   "ant automaton          <ctl-a>");
  1123.  
  1124.       choicekey[nextright+=2] = 19;
  1125.       attributes[nextright] = MENU_ITEM;
  1126.       LOADPROMPTSCHOICES(nextright,   "stereogram             <ctl-s>");
  1127.       }
  1128.  
  1129.    i = (keypressed()) ? getakey() : 0;
  1130.    if (menu_checkkey(i,0) == 0) {
  1131.       helpmode = HELPMAIN;       /* switch help modes */
  1132.       if ((nextleft += 2) < nextright)
  1133.      nextleft = nextright + 1;
  1134.       i = fullscreen_choice(CHOICEMENU+CHOICESCRUNCH,
  1135.       MAIN_MENU,
  1136.       NULL,NULL,nextleft,(char far * far *)choices,attributes,
  1137.       2,nextleft/2,29,0,NULL,NULL,NULL,menu_checkkey);
  1138.       if (i == -1)     /* escape */
  1139.      i = ESC;
  1140.       else if (i < 0)
  1141.      i = 0 - i;
  1142.       else {              /* user selected a choice */
  1143.      i = choicekey[i];
  1144.      switch (i) {          /* check for special cases */
  1145.         case -10:          /* zoombox functions */
  1146.            helpmode = HELPZOOM;
  1147.            help(0);
  1148.            i = 0;
  1149.            break;
  1150.         }
  1151.      }
  1152.       }
  1153.    if (i == ESC) {           /* escape from menu exits Fractint */
  1154.       static char far s[] = "Exit from Fractint (y/n)? y";
  1155.       helptitle();
  1156.       setattr(1,0,C_GENERAL_MED,24*80);
  1157.       for (i = 9; i <= 11; ++i)
  1158.      setattr(i,18,C_GENERAL_INPUT,40);
  1159.       putstringcenter(10,18,40,C_GENERAL_INPUT,s);
  1160.       movecursor(25,80);
  1161.       while ((i = getakey()) != 'y' && i != 'Y' && i != 13) {
  1162.      if (i == 'n' || i == 'N')
  1163.         goto top;
  1164.      }
  1165.       goodbye();
  1166.       }
  1167.    if (i == TAB) {
  1168.       tab_display();
  1169.       i = 0;
  1170.       }
  1171.    if (i == ENTER || i == ENTER_2)
  1172.       i = 0;             /* don't trigger new calc */
  1173.    tabmode = oldtabmode;
  1174.    return(i);
  1175. }
  1176.  
  1177. #if (_MSC_VER >= 700)
  1178. #pragma code_seg ()         /* back to normal segment */
  1179. #endif
  1180.  
  1181. static int menu_checkkey(int curkey,int choice)
  1182. { /* choice is dummy used by other routines called by fullscreen_choice() */
  1183.    int testkey;
  1184.    testkey = choice; /* for warning only */
  1185.    testkey = (curkey>='A' && curkey<='Z') ? curkey+('a'-'A') : curkey;
  1186. #ifdef XFRACT
  1187.    /* We use F2 for shift-@, annoyingly enough */
  1188.    if (testkey == F2) return(0-testkey);
  1189. #endif
  1190.    if (strchr("@txyzgvir3dj",testkey) || testkey == INSERT
  1191.      || testkey == ESC || testkey == DELETE)
  1192.       return(0-testkey);
  1193.    if (menutype) {
  1194.       if (strchr("\\sobpkrh",testkey) || testkey == TAB)
  1195.      return(0-testkey);
  1196.       if (testkey == ' ')
  1197.      if ((curfractalspecific->tojulia != NOFRACTAL
  1198.           && param[0] == 0.0 && param[1] == 0.0)
  1199.        || curfractalspecific->tomandel != NOFRACTAL)
  1200.      return(0-testkey);
  1201.       if (gotrealdac && colors >= 16) {
  1202.      if (strchr("c+-",testkey))
  1203.         return(0-testkey);
  1204.      if (colors > 16
  1205.        && (testkey == 'a' || (!reallyega && testkey == 'e')))
  1206.         return(0-testkey);
  1207.      }
  1208.       /* Alt-A and Alt-S */
  1209.       if (testkey == 1030 || testkey == 1031 ) 
  1210.      return(0-testkey);
  1211.       }
  1212.    if (check_vidmode_key(0,testkey) >= 0)
  1213.       return(0-testkey);
  1214.    return(0);
  1215. }
  1216.  
  1217.  
  1218. int input_field(
  1219.     int options,          /* &1 numeric, &2 integer, &4 double */
  1220.     int attr,          /* display attribute */
  1221.     char *fld,          /* the field itself */
  1222.     int len,          /* field length (declare as 1 larger for \0) */
  1223.     int row,          /* display row */
  1224.     int col,          /* display column */
  1225.     int (*checkkey)(int)  /* routine to check non data keys, or NULL */
  1226.     )
  1227. {
  1228.    char savefld[81];
  1229.    char buf[81];
  1230.    int insert, started, offset, curkey, display;
  1231.    int i, j;
  1232.    int ret,savelookatmouse;
  1233.    savelookatmouse = lookatmouse;
  1234.    lookatmouse = 0;
  1235.    ret = -1;
  1236.    strcpy(savefld,fld);
  1237.    insert = started = offset = 0;
  1238.    display = 1;
  1239.    for(;;) {
  1240.       strcpy(buf,fld);
  1241.       i = strlen(buf);
  1242.       while (i < len)
  1243.      buf[i++] = ' ';
  1244.       buf[len] = 0;
  1245.       if (display) {                    /* display current value */
  1246.      putstring(row,col,attr,buf);
  1247.      display = 0;
  1248.      }
  1249.       curkey = keycursor(row+insert,col+offset);  /* get a keystroke */
  1250.       switch (curkey) {
  1251.      case ENTER:
  1252.      case ENTER_2:
  1253.         ret = 0;
  1254.         goto inpfld_end;
  1255.      case ESC:
  1256.         goto inpfld_end;
  1257.      case RIGHT_ARROW:
  1258.      case RIGHT_ARROW_2:
  1259.         if (offset < len-1) ++offset;
  1260.         started = 1;
  1261.         break;
  1262.      case LEFT_ARROW:
  1263.      case LEFT_ARROW_2:
  1264.         if (offset > 0) --offset;
  1265.         started = 1;
  1266.         break;
  1267.      case HOME:
  1268.         offset = 0;
  1269.         started = 1;
  1270.         break;
  1271.      case END:
  1272.         offset = strlen(fld);
  1273.         started = 1;
  1274.         break;
  1275.      case 8:
  1276.      case 127:                /* backspace */
  1277.         if (offset > 0) {
  1278.            j = strlen(fld);
  1279.            for (i = offset-1; i < j; ++i)
  1280.           fld[i] = fld[i+1];
  1281.            --offset;
  1282.            }
  1283.         started = display = 1;
  1284.         break;
  1285.      case DELETE:                /* delete */
  1286.         j = strlen(fld);
  1287.         for (i = offset; i < j; ++i)
  1288.            fld[i] = fld[i+1];
  1289.         started = display = 1;
  1290.         break;
  1291.      case INSERT:                /* insert */
  1292.         insert ^= 0x8000;
  1293.         started = 1;
  1294.         break;
  1295.      case F5:
  1296.         strcpy(fld,savefld);
  1297.         insert = started = offset = 0;
  1298.         display = 1;
  1299.         break;
  1300.      default:
  1301.             if (nonalpha(curkey)) {
  1302.            if (checkkey && (ret = (*checkkey)(curkey)) != 0)
  1303.           goto inpfld_end;
  1304.            break;                     /* non alphanum char */
  1305.            }
  1306.         if (offset >= len) break;             /* at end of field */
  1307.         if (insert && started && strlen(fld) >= (size_t)len)
  1308.            break;                     /* insert & full */
  1309.         if ((options & 1)
  1310.           && (curkey < '0' || curkey > '9')
  1311.           && curkey != '+' && curkey != '-') {
  1312.            if ((options & 2))
  1313.           break;
  1314.            /* allow scientific notation, and specials "e" and "p" */
  1315.            if ( ((curkey != 'e' && curkey != 'E') || offset >= 18)
  1316.          && ((curkey != 'p' && curkey != 'P') || offset != 0 )
  1317.          && curkey != '.')
  1318.           break;
  1319.            }
  1320.         if (started == 0) /* first char is data, zap field */
  1321.            fld[0] = 0;
  1322.         if (insert) {
  1323.            j = strlen(fld);
  1324.            while (j >= offset) {
  1325.           fld[j+1] = fld[j];
  1326.           --j;
  1327.           }
  1328.            }
  1329.         if ((size_t)offset >= strlen(fld))
  1330.            fld[offset+1] = 0;
  1331.         fld[offset++] = (char)curkey;
  1332.         /* if "e" or "p" in first col make number e or pi */
  1333.         if ((options & 3) == 1) { /* floating point */
  1334.            double tmpd;
  1335.            int specialv;
  1336.            char tmpfld[30];
  1337.            specialv = 0;
  1338.            if (*fld == 'e' || *fld == 'E') {
  1339.           tmpd = exp(1.0);
  1340.           specialv = 1;
  1341.           }
  1342.            if (*fld == 'p' || *fld == 'P') {
  1343.           tmpd = atan(1.0) * 4;
  1344.           specialv = 1;
  1345.           }
  1346.            if (specialv) {
  1347.           if ((options & 4) == 0)
  1348.              roundfloatd(&tmpd);
  1349.           sprintf(tmpfld,"%.15g",tmpd);
  1350.           tmpfld[len-1] = 0; /* safety, field should be long enough */
  1351.           strcpy(fld,tmpfld);
  1352.           offset = 0;
  1353.           }
  1354.            }
  1355.         started = display = 1;
  1356.      }
  1357.       }
  1358. inpfld_end:
  1359.    lookatmouse = savelookatmouse;
  1360.    return(ret);
  1361. }
  1362.  
  1363. int field_prompt(
  1364.     int options,        /* &1 numeric value, &2 integer */
  1365.     char far *hdg,        /* heading, \n delimited lines */
  1366.     char far *instr,    /* additional instructions or NULL */
  1367.     char *fld,        /* the field itself */
  1368.     int len,        /* field length (declare as 1 larger for \0) */
  1369.     int (*checkkey)(int)   /* routine to check non data keys, or NULL */
  1370.     )
  1371. {
  1372.    char far *charptr;
  1373.    int boxwidth,titlelines,titlecol,titlerow;
  1374.    int promptcol;
  1375.    int i,j;
  1376.    char buf[81];
  1377.    helptitle();               /* clear screen, display title */
  1378.    setattr(1,0,C_PROMPT_BKGRD,24*80);      /* init rest to background */
  1379.    charptr = hdg;              /* count title lines, find widest */
  1380.    i = boxwidth = 0;
  1381.    titlelines = 1;
  1382.    while (*charptr) {
  1383.       if (*(charptr++) == '\n') {
  1384.      ++titlelines;
  1385.      i = -1;
  1386.      }
  1387.       if (++i > boxwidth)
  1388.      boxwidth = i;
  1389.       }
  1390.    if (len > boxwidth)
  1391.       boxwidth = len;
  1392.    i = titlelines + 4;              /* total rows in box */
  1393.    titlerow = (25 - i) / 2;          /* top row of it all when centered */
  1394.    titlerow -= titlerow / 4;          /* higher is better if lots extra */
  1395.    titlecol = (80 - boxwidth) / 2;      /* center the box */
  1396.    titlecol -= (90 - boxwidth) / 20;
  1397.    promptcol = titlecol - (boxwidth-len)/2;
  1398.    j = titlecol;              /* add margin at each side of box */
  1399.    if ((i = (82-boxwidth)/4) > 3)
  1400.       i = 3;
  1401.    j -= i;
  1402.    boxwidth += i * 2;
  1403.    for (i = -1; i < titlelines+3; ++i)      /* draw empty box */
  1404.       setattr(titlerow+i,j,C_PROMPT_LO,boxwidth);
  1405.    textcbase = titlecol;          /* set left margin for putstring */
  1406.    putstring(titlerow,0,C_PROMPT_HI,hdg); /* display heading */
  1407.    textcbase = 0;
  1408.    i = titlerow + titlelines + 4;
  1409.    if (instr) {               /* display caller's instructions */
  1410.       charptr = instr;
  1411.       j = -1;
  1412.       while ((buf[++j] = *(charptr++)) != 0)
  1413.      if (buf[j] == '\n') {
  1414.         buf[j] = 0;
  1415.         putstringcenter(i++,0,80,C_PROMPT_BKGRD,buf);
  1416.         j = -1;
  1417.         }
  1418.       putstringcenter(i,0,80,C_PROMPT_BKGRD,buf);
  1419.       }
  1420.    else                   /* default instructions */
  1421.       putstringcenter(i,0,80,C_PROMPT_BKGRD,
  1422.           "Press ENTER when finished (or ESCAPE to back out)");
  1423.    return(input_field(options,C_PROMPT_INPUT,fld,len,
  1424.               titlerow+titlelines+1,promptcol,checkkey));
  1425. }
  1426.  
  1427.  
  1428. /* thinking(1,message):
  1429.       if thinking message not yet on display, it is displayed;
  1430.       otherwise the wheel is updated
  1431.       returns 0 to keep going, -1 if keystroke pending
  1432.    thinking(0,NULL):
  1433.       call this when thinking phase is done
  1434.    */
  1435.  
  1436. int thinking(int options,char *msg)
  1437. {
  1438.    static int thinkstate = -1;
  1439.    static char *wheel[] = {"-","\\","|","/"};
  1440.    static int thinkcol;
  1441.    static int count = 0;
  1442.    char buf[81];
  1443.    if (options == 0) {
  1444.       if (thinkstate >= 0) {
  1445.      thinkstate = -1;
  1446.      unstackscreen();
  1447.      }
  1448.       return(0);
  1449.       }
  1450.    if (thinkstate < 0) {
  1451.       stackscreen();
  1452.       thinkstate = 0;
  1453.       helptitle();
  1454.       strcpy(buf,"  ");
  1455.       strcat(buf,msg);
  1456.       strcat(buf,"    ");
  1457.       putstring(4,10,C_GENERAL_HI,buf);
  1458.       thinkcol = textcol - 3;
  1459.       count = 0;
  1460.       }
  1461.    if ((count++)<100) {
  1462.        return 0;
  1463.    }
  1464.    count = 0;
  1465.    putstring(4,thinkcol,C_GENERAL_HI,wheel[thinkstate]);
  1466.    movecursor(25,80); /* turn off cursor */
  1467.    thinkstate = (thinkstate + 1) & 3;
  1468.    return (keypressed());
  1469. }
  1470.  
  1471.  
  1472. void clear_screen(void)  /* a stub for a windows only subroutine */
  1473. {
  1474. }
  1475.  
  1476.  
  1477. /* savegraphics/restoregraphics: video.asm subroutines */
  1478.  
  1479. static BYTE far *swapsavebuf;
  1480. static unsigned int memhandle;
  1481. unsigned long swaptotlen;
  1482. unsigned long swapoffset;
  1483. BYTE far *swapvidbuf;
  1484. int swaplength;
  1485. static int swaptype = -1;
  1486. static int swapblklen; /* must be a power of 2 */
  1487. #ifdef XFRACT
  1488. BYTE suffix[4096];
  1489. #endif
  1490.  
  1491. #ifndef XFRACT
  1492.  
  1493. int savegraphics()
  1494. {
  1495.    int i;
  1496.    struct XMM_Move   xmmparms;
  1497.  
  1498.    discardgraphics(); /* if any emm/xmm in use from prior call, release it */
  1499.    swaptotlen = (long)(vxdots > sxdots ? vxdots : sxdots) * (long)sydots;
  1500.    i = colors;
  1501.    while (i <= 16) {
  1502.       swaptotlen >>= 1;
  1503.       i = i * i;
  1504.       }
  1505.    swapoffset = 0;
  1506.    if (debugflag != 420 && debugflag != 422 /* 422=xmm test, 420=disk test */
  1507.      && (swapsavebuf = emmquery()) != NULL
  1508.      && (memhandle = emmallocate((unsigned int)((swaptotlen + 16383) >> 14)))
  1509.      != 0) {
  1510.       swaptype = 0; /* use expanded memory */
  1511.       swapblklen = 16384;
  1512.       }
  1513.    else if (debugflag != 420
  1514.      && xmmquery() != 0
  1515.      && (memhandle = xmmallocate((unsigned int)((swaptotlen + 1023) >> 10)))
  1516.      != 0) {
  1517.       swaptype = 1; /* use extended memory */
  1518.       swapblklen = 16384;
  1519.       }
  1520.    else {
  1521.       swaptype = 2; /* use disk */
  1522.       swapblklen = 4096;
  1523.  
  1524.    /* MCP 7-7-91, If 'memhandle' is an 'unsigned int', how is it ever going
  1525.       to be equal to -1?
  1526.  
  1527.       if ((memhandle = dir_open(tempdir,diskfilename,O_CREAT|O_WRONLY|O_BINARY,S_IWRITE))
  1528.      == -1) {
  1529.    */
  1530.       if ((memhandle = dir_open(tempdir,diskfilename,O_CREAT|O_WRONLY|O_BINARY,S_IWRITE))
  1531.      == 0xffff) {
  1532.  
  1533.  
  1534. dskfile_error:
  1535.      setvideotext(); /* text mode */
  1536.      setclear();
  1537.          {
  1538.             static char far s1[] = {"error in temp file "};
  1539.             static char far s2[] = { " (disk full?) - aborted\n\n"};
  1540.         printf("%Fs%s%Fs",s1,diskfilename,s2);
  1541.      }   
  1542.      exit(1);
  1543.      }
  1544.       made_dsktemp = 1;
  1545.       }
  1546.    while (swapoffset < swaptotlen) {
  1547.       swaplength = swapblklen;
  1548.       if ((swapoffset & (swapblklen-1)) != 0)
  1549.      swaplength = (int)(swapblklen - (swapoffset & (swapblklen-1)));
  1550.       if ((unsigned long)swaplength > (swaptotlen - swapoffset))
  1551.      swaplength = (int)(swaptotlen - swapoffset);
  1552.       (*swapsetup)(); /* swapoffset,swaplength -> sets swapvidbuf,swaplength */
  1553.       switch(swaptype) {
  1554.      case 0:
  1555.         emmgetpage((unsigned int)(swapoffset>>14),memhandle);
  1556.         movewords(swaplength>>1,swapvidbuf,
  1557.               swapsavebuf+(swapoffset&(swapblklen-1)));
  1558.         break;
  1559.      case 1:
  1560.         xmmparms.Length = swaplength;
  1561.         xmmparms.SourceHandle = 0; /* Source is conventional memory */
  1562.         xmmparms.SourceOffset = (unsigned long)swapvidbuf;
  1563.         xmmparms.DestHandle = memhandle;
  1564.         xmmparms.DestOffset = swapoffset;
  1565.         xmmmoveextended(&xmmparms);
  1566.         break;
  1567.      default:
  1568.         movewords(swaplength>>1,swapvidbuf,(BYTE far *)suffix);
  1569.         if (write(memhandle,suffix,swaplength) == -1)
  1570.            goto dskfile_error;
  1571.      }
  1572.       swapoffset += swaplength;
  1573.       }
  1574.    if (swaptype == 2)
  1575.       close(memhandle);
  1576.    return 0;
  1577. }
  1578.  
  1579. int restoregraphics()
  1580. {
  1581.    struct XMM_Move   xmmparms;
  1582.  
  1583.    if(swaptype == -1)
  1584.       return(-1);
  1585.    swapoffset = 0;
  1586.    if (swaptype == 2)
  1587.       memhandle = dir_open(tempdir,diskfilename,O_RDONLY|O_BINARY,S_IREAD);
  1588.    swapvidbuf = MK_FP(extraseg+0x1000,0); /* for swapnormwrite case */
  1589.    while (swapoffset < swaptotlen) {
  1590.       swaplength = swapblklen;
  1591.       if ((swapoffset & (swapblklen-1)) != 0)
  1592.      swaplength = (int)(swapblklen - (swapoffset & (swapblklen-1)));
  1593.       if ((unsigned long)swaplength > (swaptotlen - swapoffset))
  1594.      swaplength = (int)(swaptotlen - swapoffset);
  1595.       if (swapsetup != swapnormread)
  1596.      (*swapsetup)(); /* swapoffset,swaplength -> sets swapvidbuf,swaplength */
  1597.       switch(swaptype) {
  1598.      case 0:
  1599.         emmgetpage((unsigned int)(swapoffset>>14),memhandle);
  1600.         movewords(swaplength>>1,swapsavebuf+(swapoffset&(swapblklen-1)),
  1601.               swapvidbuf);
  1602.         break;
  1603.      case 1:
  1604.         xmmparms.Length = swaplength;
  1605.         xmmparms.SourceHandle = memhandle;
  1606.         xmmparms.SourceOffset = swapoffset;
  1607.         xmmparms.DestHandle = 0; /* conventional memory */
  1608.         xmmparms.DestOffset = (unsigned long)swapvidbuf;
  1609.         xmmmoveextended(&xmmparms);
  1610.         break;
  1611.      default:
  1612.         read(memhandle,suffix,swaplength);
  1613.         movewords(swaplength>>1,(BYTE far *)suffix,swapvidbuf);
  1614.      }
  1615.       if (swapsetup == swapnormread)
  1616.      swapnormwrite();
  1617.       swapoffset += swaplength;
  1618.       }
  1619.    if (swaptype == 2)
  1620.       close(memhandle);
  1621.    discardgraphics();
  1622.    return(0);
  1623. }
  1624.  
  1625. #else
  1626. int savegraphics() {return 0;}
  1627. int restoregraphics() {return 0;}
  1628. #endif
  1629.  
  1630. void discardgraphics() /* release expanded/extended memory if any in use */
  1631. {
  1632. #ifndef XFRACT
  1633.    switch(swaptype) {
  1634.       case 0:
  1635.      emmdeallocate(memhandle);
  1636.      break;
  1637.       case 1:
  1638.      xmmdeallocate(memhandle);
  1639.       }
  1640.    swaptype = -1;
  1641. #endif
  1642. }
  1643.  
  1644. #if (_MSC_VER >= 700)
  1645. #pragma code_seg ("realdos1_text")     /* place following in an overlay */
  1646. #endif
  1647.  
  1648. VIDEOINFO *vidtbl;  /* temporarily loaded fractint.cfg info */
  1649. int vidtbllen;               /* number of entries in above           */
  1650.  
  1651. int showvidlength()
  1652. {
  1653.    int sz;
  1654.    sz = (sizeof(VIDEOINFO)+sizeof(int))*MAXVIDEOMODES;
  1655.    return(sz);
  1656. }
  1657.  
  1658. int load_fractint_cfg(int options)
  1659. {
  1660.    /* Reads fractint.cfg, loading videoinfo entries into extraseg. */
  1661.    /* Sets vidtbl pointing to the loaded table, and returns the    */
  1662.    /* number of entries (also sets vidtbllen to this).           */
  1663.    /* Past vidtbl, cfglinenums are stored for update_fractint_cfg. */
  1664.    /* If fractint.cfg is not found or invalid, issues a message    */
  1665.    /* (first time the problem occurs only, and only if options is  */
  1666.    /* zero) and uses the hard-coded table.               */
  1667.  
  1668.    FILE *cfgfile;
  1669.    VIDEOINFO *vident;
  1670.    int far *cfglinenums;
  1671.    int linenum;
  1672.    int i, j, keynum, ax, bx, cx, dx, dotmode, xdots, ydots, colors;
  1673.    int commas[10];
  1674.    int textsafe2;
  1675.    char tempstring[150];
  1676.  
  1677.    vidtbl = MK_FP(extraseg,0);
  1678.    cfglinenums = (int far *)(&vidtbl[MAXVIDEOMODES]);
  1679.  
  1680. #ifdef XFRACT
  1681.     badconfig = -1;
  1682. #endif
  1683.  
  1684.    if (badconfig)  /* fractint.cfg already known to be missing or bad */
  1685.       goto use_resident_table;
  1686.  
  1687.    findpath("fractint.cfg",tempstring);
  1688.    if (tempstring[0] == 0                 /* can't find the file */
  1689.      || (cfgfile = fopen(tempstring,"r")) == NULL)   /* can't open it */
  1690.       goto bad_fractint_cfg;
  1691.  
  1692.    vidtbllen = 0;
  1693.    linenum = 0;
  1694.    vident = vidtbl;
  1695.    while (vidtbllen < MAXVIDEOMODES
  1696.      && fgets(tempstring, 120, cfgfile)) {
  1697.       ++linenum;
  1698.       if (tempstring[0] == ';') continue;   /* comment line */
  1699.       tempstring[120] = 0;
  1700.       tempstring[strlen(tempstring)-1] = 0; /* zap trailing \n */
  1701.       memset(commas,0,20);
  1702.       i = j = -1;
  1703.       for(;;) {
  1704.      if (tempstring[++i] < ' ') {
  1705.         if (tempstring[i] == 0) break;
  1706.         tempstring[i] = ' '; /* convert tab (or whatever) to blank */
  1707.         }
  1708.      else if (tempstring[i] == ',' && ++j < 10) {
  1709.         commas[j] = i + 1;     /* remember start of next field */
  1710.         tempstring[i] = 0;     /* make field a separate string */
  1711.         }
  1712.      }
  1713.       keynum = check_vidmode_keyname(tempstring);
  1714.       sscanf(&tempstring[commas[1]],"%x",&ax);
  1715.       sscanf(&tempstring[commas[2]],"%x",&bx);
  1716.       sscanf(&tempstring[commas[3]],"%x",&cx);
  1717.       sscanf(&tempstring[commas[4]],"%x",&dx);
  1718.       dotmode      = atoi(&tempstring[commas[5]]);
  1719.       xdots      = atoi(&tempstring[commas[6]]);
  1720.       ydots      = atoi(&tempstring[commas[7]]);
  1721.       colors      = atoi(&tempstring[commas[8]]);
  1722.       textsafe2   = dotmode / 100;
  1723.       dotmode     %= 100;
  1724.       if (j != 9 ||
  1725.         keynum < 0 ||
  1726.         dotmode < 0 || dotmode > 30 ||
  1727.         textsafe2 < 0 || textsafe2 > 4 ||
  1728.         xdots < 160 || xdots > MAXPIXELS ||
  1729.         ydots < 160 || ydots > MAXPIXELS ||
  1730.         (colors != 0 && colors != 2 && colors != 4 && colors != 16 &&
  1731.          colors != 256)
  1732.        )
  1733.      goto bad_fractint_cfg;
  1734.       cfglinenums[vidtbllen] = linenum; /* for update_fractint_cfg */
  1735.       far_memcpy(vident->name,     (char far *)&tempstring[commas[0]],25);
  1736.       far_memcpy(vident->comment,(char far *)&tempstring[commas[9]],25);
  1737.       vident->name[25] = vident->comment[25] = 0;
  1738.       vident->keynum      = keynum;
  1739.       vident->videomodeax = ax;
  1740.       vident->videomodebx = bx;
  1741.       vident->videomodecx = cx;
  1742.       vident->videomodedx = dx;
  1743.       vident->dotmode      = textsafe2 * 100 + dotmode;
  1744.       vident->xdots      = xdots;
  1745.       vident->ydots      = ydots;
  1746.       vident->colors      = colors;
  1747.       ++vident;
  1748.       ++vidtbllen;
  1749.       }
  1750.    fclose(cfgfile);
  1751.    return (vidtbllen);
  1752.  
  1753. bad_fractint_cfg:
  1754.    badconfig = -1; /* bad, no message issued yet */
  1755.    if (options == 0)
  1756.       bad_fractint_cfg_msg();
  1757.  
  1758. use_resident_table:
  1759.    vidtbllen = 0;
  1760.    vident = vidtbl;
  1761.    for (i = 0; i < MAXVIDEOTABLE; ++i) {
  1762.       if (videotable[i].xdots) {
  1763.      far_memcpy((char far *)vident,(char far *)&videotable[i],
  1764.             sizeof(*vident));
  1765.      ++vident;
  1766.      ++vidtbllen;
  1767.      }
  1768.       }
  1769.    return (vidtbllen);
  1770.  
  1771. }
  1772.  
  1773. void bad_fractint_cfg_msg()
  1774. {
  1775. static char far badcfgmsg[]={"\
  1776. File FRACTINT.CFG is missing or invalid.\n\
  1777. See Hardware Support and Video Modes in the full documentation for help.\n\
  1778. I will continue with only the built-in video modes available."};
  1779.    stopmsg(0,badcfgmsg);
  1780.    badconfig = 1; /* bad, message issued */
  1781. }
  1782.  
  1783. void load_videotable(int options)
  1784. {
  1785.    /* Loads fractint.cfg and copies the video modes which are */
  1786.    /* assigned to function keys into videotable.          */
  1787.    int keyents,i;
  1788.    load_fractint_cfg(options); /* load fractint.cfg to extraseg */
  1789.    keyents = 0;
  1790.    far_memset((char far *)videotable,0,sizeof(*vidtbl)*MAXVIDEOTABLE);
  1791.    for (i = 0; i < vidtbllen; ++i) {
  1792.       if (vidtbl[i].keynum > 0) {
  1793.      far_memcpy((char far *)&videotable[keyents],(char far *)&vidtbl[i],
  1794.             sizeof(*vidtbl));
  1795.      if (++keyents >= MAXVIDEOTABLE)
  1796.         break;
  1797.      }
  1798.       }
  1799. }
  1800.  
  1801. int check_vidmode_key(int option,int k)
  1802. {
  1803.    int i;
  1804.    /* returns videotable entry number if the passed keystroke is a  */
  1805.    /* function key currently assigned to a video mode, -1 otherwise */
  1806.    if (k == 1400)           /* special value from select_vid_mode  */
  1807.       return(MAXVIDEOTABLE-1); /* for last entry with no key assigned */
  1808.    if (k != 0)
  1809.       if (option == 0) { /* check resident video mode table */
  1810.      for (i = 0; i < MAXVIDEOTABLE; ++i) {
  1811.         if (videotable[i].keynum == k)
  1812.            return(i);
  1813.         }
  1814.      }
  1815.       else { /* check full vidtbl */
  1816.      for (i = 0; i < vidtbllen; ++i) {
  1817.         if (vidtbl[i].keynum == k)
  1818.            return(i);
  1819.         }
  1820.      }
  1821.    return(-1);
  1822. }
  1823.  
  1824. int check_vidmode_keyname(char *kname)
  1825. {
  1826.    /* returns key number for the passed keyname, 0 if not a keyname */
  1827.    int i,keyset;
  1828.    keyset = 1058;
  1829.    if (*kname == 'S' || *kname == 's') {
  1830.       keyset = 1083;
  1831.       ++kname;
  1832.       }
  1833.    else if (*kname == 'C' || *kname == 'c') {
  1834.       keyset = 1093;
  1835.       ++kname;
  1836.       }
  1837.    else if (*kname == 'A' || *kname == 'a') {
  1838.       keyset = 1103;
  1839.       ++kname;
  1840.       }
  1841.    if (*kname != 'F' && *kname != 'f')
  1842.       return(0);
  1843.    if (*++kname < '1' || *kname > '9')
  1844.       return(0);
  1845.    i = *kname - '0';
  1846.    if (*++kname != 0 && *kname != ' ') {
  1847.       if (*kname != '0' || i != 1)
  1848.      return(0);
  1849.       i = 10;
  1850.       ++kname;
  1851.       }
  1852.    while (*kname)
  1853.       if (*(kname++) != ' ')
  1854.      return(0);
  1855.    if ((i += keyset) < 2)
  1856.       i = 0;
  1857.    return(i);
  1858. }
  1859.  
  1860. void vidmode_keyname(int k,char *buf)
  1861. {
  1862.    /* set buffer to name of passed key number */
  1863.    *buf = 0;
  1864.    if (k > 0) {
  1865.       if (k > 1103) {
  1866.      *(buf++) = 'A';
  1867.      k -= 1103;
  1868.      }
  1869.       else if (k > 1093) {
  1870.      *(buf++) = 'C';
  1871.      k -= 1093;
  1872.      }
  1873.       else if (k > 1083) {
  1874.      *(buf++) = 'S';
  1875.      k -= 1083;
  1876.      }
  1877.       else
  1878.      k -= 1058;
  1879.       sprintf(buf,"F%d",k);
  1880.       }
  1881. }
  1882.  
  1883. #if (_MSC_VER >= 700)
  1884. #pragma code_seg ()      /* back to normal segment */
  1885. #endif
  1886.